package com.example.administrator.schoolblog;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.administrator.schoolblog.Beans.BlogUser;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.QueryListener;
import de.hdodenhof.circleimageview.CircleImageView;

public class OtherinfoActivity extends BaseActivity {
    private String userId;
    private CircleImageView userIcon;
    private TextView nickName;
    private TextView birth;
    private TextView school;
    private TextView yuan;
    private TextView email;
    private TextView sign;
    private ImageView sex;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            window.setStatusBarColor(getResources().getColor(R.color.colorPrimary));
        }
        setContentView(R.layout.blog_other_info);
        Bmob.initialize(this,"b5d62a501dc94902d3f8672a1b5fc2ab","Bmob");
        Intent new_intent = getIntent();
        userId = new_intent.getStringExtra("userId");
        initView();
        refreshOtherInfo();
    }
    private void initView(){
        Toolbar toolbar =(Toolbar) findViewById(R.id.blog_other_toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        if(actionBar!=null){
            actionBar.setDisplayHomeAsUpEnabled(true);
            //actionBar.setDisplayShowTitleEnabled(false);
        }
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        FloatingActionButton floatingActionButton = (FloatingActionButton) findViewById(R.id.other_user_fab);
        floatingActionButton.setVisibility(View.VISIBLE);
        userIcon = (CircleImageView) findViewById(R.id.other_avatar);
        nickName = (TextView) findViewById(R.id.other_nickname);
        birth = (TextView) findViewById(R.id.other_birth);
        school = (TextView) findViewById(R.id.other_school);
        school.setText("西北师范大学");
        yuan = (TextView) findViewById(R.id.other_yuan);
        email = (TextView) findViewById(R.id.other_email);
        sign = (TextView) findViewById(R.id.other_sign);
        sex = (ImageView) findViewById(R.id.other_sex);
    }
    private void refreshOtherInfo(){
        BmobQuery<BlogUser> other_info = new BmobQuery<BlogUser>();
        other_info.getObject(userId, new QueryListener<BlogUser>() {
            @Override
            public void done(BlogUser blogUser, BmobException e) {
                if(e==null){
                    if(blogUser.getUserIconUrl()!=null){
                        Glide.with(OtherinfoActivity.this).load(blogUser.getUserIconUrl()).into(userIcon);
                    }
                    nickName.setText(blogUser.getNickname());
                    if (blogUser.getBirthday()!=null){
                        birth.setText(blogUser.getBirthday());
                    }
                    if (blogUser.getEmail()!=null){
                        email.setText(blogUser.getEmail());
                    }
                    if (blogUser.getCollege()!=null){
                        yuan.setText(blogUser.getCollege());
                    }
                    if (blogUser.getSignature()!=null){
                        sign.setText(blogUser.getSignature());
                    }
                    if (blogUser.getSex()!=null&&blogUser.getSex().equals("女")==true){
                        Glide.with(OtherinfoActivity.this).load(R.drawable.ic_sex_girl);
                    }
                }
            }
        });
    }
}
